#include "list.h"
#include <math.h>

const __int64 H = 1000;

struct hashtable {

	list a[H];

	void add(char t[]) {
		__int64 k = get_hash(t);

		node *p = NULL;

		p = a[k].search(t);
		if (p) 
			p->count++;
		else 
			a[k].push_back(t);
	}

	__int64 get_hash(char l[]) {
		__int64 k = 0;
		for (__int64 i = 0; l[i]; i++) 
			k += l[i] * pow(8.0, double(i));
		if (k >= 0) 
			return k % H;
		else 
			return (-k) % H;
	}

	void show_count() {
		node* p;
		for(__int64 i = 0; i < H; ++i) {
			if(a[i].head != NULL) {
				p = a[i].head;
				while(p != NULL) {
					printf("%s - %d times\n", p->value, p->count);
					p = p->next;
				}
			}
		}
	}
};
